package com.kehao.leetcode.basic.others;

import org.junit.Test;

import java.util.Stack;

public class VaildBracketSolution {
    public boolean isValid(String s) {
        char[] charArray = s.toCharArray();
        Stack<Character> stack = new Stack();
        for (int i = 0; i < charArray.length; i++) {
            if(!stack.empty()){
                if(
                        (charArray[i]==')'&&stack.peek()=='(')||
                        (charArray[i]=='}'&&stack.peek()=='{')||
                        (charArray[i]==']'&&stack.peek()=='[')
                ){
                    stack.pop();
                    continue;
                }
            }
            stack.push(charArray[i]);

        }
        return stack.empty();
    }

    @Test
    public void test01(){
        String s = "({[)";
        System.out.println(isValid(s));
    }
}
